import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  ModelList,
  ModelInfo,
  ModelEnable,
  ModelUserId,
  ModelUserPower,
  ModelUserPassword,
} from "./types";

// 用户管理 - 查询列表
export function getUserList(
  data: ModelList
): AxiosPromise<Record<string, any>> {
  return request({
    url: "/api/backend/admin/user/get-page",
    method: "post",
    data,
  });
}

// 用户管理 - 新增用户
export function addUser(data: ModelInfo): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/user/add`,
    method: "post",
    data,
  });
}

// 用户管理 - 修改用户
export function updateUser(data: ModelInfo): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/user/update`,
    method: "put",
    data,
  });
}

// 用户管理 - 获取角色
export function getRoles({}): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/role/internal-get-list`,
    method: "get",
    params: {},
  });
}

// 用户管理 - 获取角色
export function getUserInfo(
  data: ModelUserId
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/user/get`,
    method: "get",
    params: data,
  });
}

// 用户管理 启用禁用
export function setEnable(
  data: ModelEnable
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/user/set-enable`,
    method: "post",
    data,
  });
}

// 用户管理  重置密码
export function resetPassword(
  data: ModelUserId
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/user/reset-password`,
    method: "post",
    data,
  });
}

// 用户管理  获取用户数据权限
export function getUserPower(data: number): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/Users/scope/${data}`,
    method: "get",
  });
}

// 用户管理  设置用户数据权限
export function setUserPower(
  data: ModelUserPower
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/Users/scope/${data.id}`,
    method: "put",
    data,
  });
}

// 用户管理  修改用户密码
export function updatePassword(
  data: ModelUserPassword
): AxiosPromise<Record<string, any>> {
  return request({
    url: `/api/backend/admin/user/change-password`,
    method: "put",
    data,
  });
}
